<?php

/*
 * Created on 08.01.2007
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 *
 * <example:bodyProcess></example:bodyProcess>
 */

m2import('phpinchains/psp/MethodTag.php');

class cms_geturibyhrefHandler extends phpinchains_psp_MethodTag {

    /**
     * Is a body tag (if false, body is ignored)
     */
    var $tagType = PSP_EMPTY_TAG;
    /**
     * Tag name in form namespace:tagname
     */
    var $tagName = 'cms:geturibyhref';
    var $requiredAttributes = array(
        'href' => 'pageid:\d+'
    );
    var $attributes = array(
        'var'
    );
    private $dba;

    function doStartTag() {
        preg_match('/pageid:(\d+)/', $this->getAttribute('href'), $matches);
        $link_id = $matches[1];
        $ctx = base_ApplicationContext::getInstance();
        $env = $ctx->getEnvWrapper();
        $this->dba = $ctx->getAccessFactory()->getInstanceOf(base_AccessFactory::$CMS);
        $dctx = $ctx->getDocumentContext();
        $this->related_docs[] = $link_id;
        $this->registerRelatedDocuments($dctx);
        $link = base_templateEngine_TemplateEngineLinkBuilder::buildPageLink($dctx->getRoot()->getBuildMode(), $link_id);
        if ($this->getAttribute('var'))
            $this->actionform->set($this->getAttribute('var'), $link);
        else
            $this->out->write($link);
        return PSP_SKIP_BODY;
    }

    function doEndTag() {
        return PSP_SKIP_BODY;
    }

}

?>